package edu.co.uniandes.taller14.web;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.corba.se.impl.javax.rmi.PortableRemoteObject;

import edu.co.uniandes.taller14.ejb.Directorio;
import edu.co.uniandes.taller14.ejb.DirectorioHome;

/**
 * Servlet implementation class DirectorioServlet
 */
public class DirectorioServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DirectorioServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doGet(request, response);
		
		try {
			
	         InitialContext ic = new InitialContext();
	         Object objRef = ic.lookup("java:comp/env/ejb/Directorio");
	         PortableRemoteObject pro = new PortableRemoteObject();
	         DirectorioHome home = (DirectorioHome)pro.narrow(objRef, DirectorioHome.class);
	         Directorio directorio = home.create(request.getParameter("directorioID"), request.getParameter("nombre"), request.getParameter("departamento"), request.getParameter("oficina"), request.getParameter("extension"));
			
			request.getRequestDispatcher("/directorio.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}

		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(request, response);
	}

}
